function! api#whichkey#init() abort
    " WhichKey:" {{{
    if !exists('g:loaded_vim_which_key')
        try
            packadd vim-which-key
        catch /.*/
        endtry
    endif
    if exists('g:loaded_vim_which_key') && g:loaded_vim_which_key
        call s:space_keymap()
        call which_key#register(' ', 'g:space_keymap')
        nnoremap <Space> :<C-u>WhichKey ' '<cr>
        vnoremap <Space> :<C-u>WhichKey ' '<cr>
    endif
    " }}}
endfunction

function! s:space_keymap() abort
    " space_keymap
    let g:space_keymap = get(g:, "space_keymap", { "name" : "+space" })
    " async
    let g:async_keymap   = get(g:, "async_keymap", { "name" : "+async" })
    let g:async_keymap.p = [':exe "normal "."\"+p"', 'paste']
    let g:async_keymap.y = [':exe "normal "."\"+Y"', 'yank']
    let g:async_keymap.r = [':call api#enter#on_vim()', 'reload']
    let g:space_keymap.a = g:async_keymap 
    " buffer
    let g:buffer_keymap = get(g:, "buffer_keymap", { "name": "+buffer" })
    let g:buffer_keymap.d = [':bd', 'delete']
    let g:buffer_keymap.l = [':buffers', 'list']
    let g:buffer_keymap.n = [':bnext', 'next']
    let g:buffer_keymap.p = [':bprevious', 'previous']
    let g:space_keymap.b = g:buffer_keymap
    " file
    let g:file_keymap = get(g:, "file_keymap", { "name": "+file" })
    let g:file_keymap.w = [':w', 'write']
    let g:file_keymap.s = [':source %', 'source']
    let g:space_keymap.f = g:file_keymap
    " quit
    let g:quit_keymap = get(g:, "quit_keymap", { "name" : "+quit" })
    let g:quit_keymap.q = [":q", "quit"]
    let g:quit_keymap.f = [":q!", "force-quit"]
    let g:space_keymap.q = g:quit_keymap
endfunction

